/**
*  
* @Function 数据采集服务 
* @ProjectName credit-data-platform 
* @PackageName com.py.credit.service.impl    
* @FileName DataCollectionServiceImpl.java    
* @Date 2018年6月22日下午12:03:20
* @Author Min DongXv
* @Copyright (c) 2018, 金电联行 All Rights Reserved.   
*   
*/
package com.py.credit.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.py.credit.dao.DataCollectionDao;
import com.py.credit.entity.SysUser;
import com.py.credit.service.DataCollectionService;
import com.py.credit.utils.DateUtils;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;

/**
 * 
 * @Function 数据采集服务
 * @ClassName DataCollectionServiceImpl
 * @Date 2018年6月22日 下午12:03:20
 * @Author Min DongXv
 * 
 */
@Service
public class DataCollectionServiceImpl implements DataCollectionService {

	@Autowired
	private DataCollectionDao dataCollectionDao;

	/**
	 *
	 * @Function 获取数据采集列表
	 * @FileName BatchLogServiceImpl.java
	 * @MethodName getResourceListByConditionForPage
	 * @param userInfo
	 *            用户信息实体
	 * @param isFinish
	 *            是否完成 1:已完成 0:未完成
	 * @param rootId
	 *            库ID
	 * @param condition
	 *            普通查询条件
	 * @param page
	 *            分页
	 * @return
	 * @Date 2018年6月22日 上午11:38:28
	 * @Author Min DongXv
	 *
	 */
	@Override
	public List<Map<String, Object>> getResourceListByConditionForPage(SysUser userInfo, Integer isFinish,
			Integer rootId, String condition, Page page, List<String> columns, String[] additionalColumns,String rolename) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		Long topDeptId = userInfo.getOfficeId();
		// 获取父部门ID
		String pIds = userInfo.getAllParentId();
		if (StringUtils.isNotBlank(pIds)) {
			String t = StringUtils.split(pIds, ",")[0];
			topDeptId = StringUtils.isNoneBlank(t) ? Long.valueOf(t) : topDeptId;
		}
		String startTime = DateUtils.getDay(true, 0, DateUtils.STANDADD_PATTERN);
		String endTime = DateUtils.getDay(true, 1, DateUtils.STANDADD_PATTERN);
		Map<String, Object> params = new HashMap<String, Object>(8);
		params.put("startTime", startTime);
		params.put("endTime", endTime);
		if(rolename!=null&&!rolename.equals("系统管理员")) {
			params.put("regionId", userInfo.getAreaId());
			params.put("deptId", userInfo.getOfficeId());
			params.put("topDeptId", topDeptId);
		}else {
			params.put("regionId", "");
			params.put("deptId", "");
			params.put("topDeptId", "");
		}
	
		params.put("isFinish", isFinish);
		params.put("rootId", rootId);
		params.put("userType", userInfo.getUserType());
		return dataCollectionDao.getResourceListByConditionForPage(conditions, page, columns, additionalColumns,
				params);
	}

	@Override
	public List<Map<String, Object>> getDoubleResourceListByConditionForPage(SysUser userInfo, Integer isFinish, Integer rootId, String condition, Page page, List<String> columns, String[] additionalColumns, String rolename) {
			List<String> conditions = SQLBuilder.createConditionSql(condition);
			Long topDeptId = userInfo.getOfficeId();
			// 获取父部门ID
			String pIds = userInfo.getAllParentId();
			if (StringUtils.isNotBlank(pIds)) {
				String t = StringUtils.split(pIds, ",")[0];
				topDeptId = StringUtils.isNoneBlank(t) ? Long.valueOf(t) : topDeptId;
			}
			String startTime = DateUtils.getDay(true, 0, DateUtils.STANDADD_PATTERN);
			String endTime = DateUtils.getDay(true, 1, DateUtils.STANDADD_PATTERN);
			Map<String, Object> params = new HashMap<String, Object>(8);
			params.put("startTime", startTime);
			params.put("endTime", endTime);
			if(rolename!=null&&!rolename.equals("系统管理员")) {
				params.put("regionId", userInfo.getAreaId());
				params.put("deptId", userInfo.getOfficeId());
				params.put("topDeptId", topDeptId);
			}else {
				params.put("regionId", "");
				params.put("deptId", "");
				params.put("topDeptId", "");
			}

			params.put("isFinish", isFinish);
			params.put("rootId", rootId);
			params.put("userType", userInfo.getUserType());
			return dataCollectionDao.getDoubleResourceListByConditionForPage(conditions, page, columns, additionalColumns,
					params);
	}

	@Override
	public List<Map<String, Object>> getDoubleFrResourceListByConditionForPage(SysUser userInfo, Integer isFinish, Integer rootId, String condition, Page page, List<String> columns, String[] additionalColumns, String rolename) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		Long topDeptId = userInfo.getOfficeId();
		// 获取父部门ID
		String pIds = userInfo.getAllParentId();
		if (StringUtils.isNotBlank(pIds)) {
			String t = StringUtils.split(pIds, ",")[0];
			topDeptId = StringUtils.isNoneBlank(t) ? Long.valueOf(t) : topDeptId;
		}
		String startTime = DateUtils.getDay(true, 0, DateUtils.STANDADD_PATTERN);
		String endTime = DateUtils.getDay(true, 1, DateUtils.STANDADD_PATTERN);
		Map<String, Object> params = new HashMap<String, Object>(8);
		params.put("startTime", startTime);
		params.put("endTime", endTime);
		if(rolename!=null&&!rolename.equals("系统管理员")) {
			params.put("regionId", userInfo.getAreaId());
			params.put("deptId", userInfo.getOfficeId());
			params.put("topDeptId", topDeptId);
		}else {
			params.put("regionId", "");
			params.put("deptId", "");
			params.put("topDeptId", "");
		}

		params.put("isFinish", isFinish);
		params.put("rootId", rootId);
		params.put("userType", userInfo.getUserType());
		return dataCollectionDao.getDoubleFrResourceListByConditionForPage(conditions, page, columns, additionalColumns,
				params);
	}

	@Override
	public List<Map<String, Object>> getTcountGroupByDept() {
		return dataCollectionDao.getTcountGroupByDept();
	}

	@Override
	public List<Map<String, Object>> getTenResourceListByConditionForPage(SysUser userInfo, Integer isFinish,
			Integer rootId, String condition, Page page, List<String> columns, String[] additionalColumns,String rolename) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		Long topDeptId = userInfo.getOfficeId();
		// 获取父部门ID
		String pIds = userInfo.getAllParentId();
		if (StringUtils.isNotBlank(pIds)) {
			String t = StringUtils.split(pIds, ",")[0];
			topDeptId = StringUtils.isNoneBlank(t) ? Long.valueOf(t) : topDeptId;
		}
		String startTime = DateUtils.getDay(true, 0, DateUtils.STANDADD_PATTERN);
		String endTime = DateUtils.getDay(true, 1, DateUtils.STANDADD_PATTERN);
		Map<String, Object> params = new HashMap<String, Object>(8);
		params.put("startTime", startTime);
		params.put("endTime", endTime);
		if(rolename!=null&&!rolename.equals("系统管理员")) {
			params.put("regionId", userInfo.getAreaId());
			params.put("deptId", userInfo.getOfficeId());
			params.put("topDeptId", topDeptId);
		}else {
			params.put("regionId", "");
			params.put("deptId", "");
			params.put("topDeptId", "");
		}

		params.put("isFinish", isFinish);
		params.put("rootId", rootId);
		params.put("userType", userInfo.getUserType());
		return dataCollectionDao.getTenResourceListByConditionForPage(conditions, page, columns, additionalColumns,
				params);
	}
	
	

}
